package com.jxwifi.cloud.quickclean.main;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

import com.basicactivity.BasicActivity;
import com.jxwifi.cloud.quickclean.MainActivity;
import com.jxwifi.cloud.quickclean.R;
import com.jxwifi.cloud.quickclean.app.AccountMgr;
import com.jxwifi.cloud.quickclean.app.ClientBasicActivity;
import com.jxwifi.cloud.quickclean.login.LoginActivity;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 用户协议
 */
public class MainUserActivity extends ClientBasicActivity {

    @Bind(R.id.lucky_web)
    WebView mLuckWeb;
    private int agreementId;
    @Bind(R.id.agreementTitle)
    TextView agreementTitle;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_user);
        ButterKnife.bind(this);
        openEventBus();
          //http://admin.kjb.tilted.cn/resource/cleaner.html

        String sID=getIntent().getStringExtra("agreementId");
        String title = getIntent().getStringExtra("title");
        String positionUrl = getIntent().getStringExtra("positionUrl");
        if(null != sID){
            agreementId=Integer.parseInt(sID);
        }
        if(agreementId == 2) {
            agreementTitle.setText("隐私政策");
            //暂无隐私政策网址，先用用户服务协议
            mLuckWeb.loadUrl("https://ui.qcleaner.cn/resource/cleaner.html");
        }else if(agreementId == 3){
            agreementTitle.setText(title);
            mLuckWeb.loadUrl(positionUrl);
        }else{
            //用户协议
            mLuckWeb.loadUrl("https://ui.qcleaner.cn/resource/client.html");
        }
        mLuckWeb.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return super.shouldOverrideUrlLoading(view, url);
            }

        });

    }

    @OnClick({R.id.rel_img_back_pressed})
    void clickCK(View v) {
        switch (v.getId()) {
            case R.id.rel_img_back_pressed:
                if(agreementId == 3){
                    toNextAc();
                }
                onBackPressed();
                break;
        }
    }

    public void toNextAc(){
        if (AccountMgr.isLogin(mBaseContext)){
            Intent intent = new Intent();
            intent.setClass(mBaseContext,MainActivity.class);
            startActivity(intent);
            overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);//处理广告页中的启动动画，添加这个可以去掉系统的默认加载动画
            finish();
        }else{
            Intent intent = new Intent();
            intent.setClass(mBaseContext,LoginActivity.class);
            startActivity(intent);
            overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);//处理广告页中的启动动画，添加这个可以去掉系统的默认加载动画
            finish();
        }
    }
}
